#include"server.hpp"

#define HOST "127.0.0.1"
#define USRNAME "root"
#define PASSWORD "zpk20020629"
#define DBNAME "gobang"
#define PORT 3306

int testmysql()
{
	MYSQL *mysql = Mysql_util::mysql_create(HOST, USRNAME, PASSWORD, DBNAME, PORT);
	const char *sql1 = "insert stu values(null,'张三',19,66,88,99)";
	bool ret1 = Mysql_util::Mysql_exec(mysql, sql1);
	if (ret1 == false)
		return -1;

	const char *sql2 = "insert stu values(null,'李四',22,98,99,87)";
	bool ret2 = Mysql_util::Mysql_exec(mysql, sql2);
	if (ret2 == false)
		return -1;

	bool n = Mysql_util::Mysql_destroy(mysql);
	return 0;
}

int testJson()
{
	Json::Value root;
	root["姓名"] = "张三";
	root["年龄"] = 18;
	root["分数"].append(85.8);
	root["分数"].append(99.6);
	root["分数"].append(78.5);

	string lize;
	Json_util ::serialize(root, lize);

	cout << "序列化后结果" << endl;					
	DLOG("%s", lize.c_str());

	Json::Value getback;
	Json_util ::unserialize(lize, getback);
	cout << "姓名：" << getback["姓名"].asString() << endl;
	cout << "年龄:" << getback["年龄"].asInt() << endl;
	for (int i = 0; i < getback["分数"].size(); ++i)
	{
		cout << "分数" << getback["分数"][i].asFloat() << endl;
	}
}


int testsepstr()
{
	string str = "this is the sentence, whitch need to be sep,,,,,11116151,,151,,15,131.12,,12,";
	vector<string> contain;
	int ret = Str_util :: sepstring(str,",", contain);
	
	cout<<"ret : "<<ret <<endl;

	for(auto& e : contain) cout<<e<<endl;
}

int testfileread()
{
	string filename = "log.hpp";
	string getback;
	File_util::read(filename,getback);


	cout<<filename<<":";
	cout<<getback<<endl;

	return 0;
}

void testdb()
{
	user_table ut(HOST, USRNAME, PASSWORD, DBNAME, PORT);
	Json::Value user;
	// user["password"] ="12345678915615";
	// bool ret = ut.insert(user);
	// bool ret =  ut.select_by_name("张哥",user);
	bool ret = ut.lose(1);
	// bool ret = ut.win(1);

	if(ret == false)
	{
		DLOG("insert Failed!");
		return;
	}
	//不序列化输出就是一个个的，序列化后就是一个格式化的字符串
	string body;
	Json_util::serialize(user,body);
	cout<<body<<endl;

}


// uint64_t white_id, uint64_t black_id, uint64_t room_id, online_manager *olmanager, user_table *usrt
void testroom()
{
	online_manager om;
	user_table ut(HOST, USRNAME, PASSWORD, DBNAME, PORT);

	room r(10,&om,&ut);
	room_manager rmm(&ut,&om);
	rmm.room_create(20,60);

	matcher mt(&om,&ut,&rmm);
}



int main()
{
	gobang_server gser(HOST, USRNAME, PASSWORD, DBNAME, PORT);
	gser.start(8080);
	return 0;
}
